﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<UserControl x:Class="System.Windows.Controls.Samples.DataGridGroupingSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:datagrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <StackPanel>
        <ContentControl Content="DataGrid with Grouping" Style="{StaticResource Header}" />
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0">
                <CheckBox Content="AreRowDetailsFrozen" IsChecked="{Binding AreRowDetailsFrozen, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <CheckBox Content="AreRowGroupHeadersFrozen" IsChecked="{Binding AreRowGroupHeadersFrozen, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <CheckBox Content="CanUserReorderColumns" IsChecked="{Binding CanUserReorderColumns, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <CheckBox Content="CanUserResizeColumns" IsChecked="{Binding CanUserResizeColumns, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <CheckBox Content="CanUserSortColumns" IsChecked="{Binding CanUserSortColumns, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <TextBlock Style="{StaticResource ApiName}" Text="FrozenColumnCount" Margin="4" />
                <input:NumericUpDown VerticalAlignment="Center" Minimum="0" Margin="4" Value="{Binding FrozenColumnCount, ElementName=dataGrid, Mode=TwoWay}" />
                <CheckBox Content="IsReadOnly" IsChecked="{Binding IsReadOnly, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <CheckBox Content="IsValid" IsChecked="{Binding IsValid, ElementName=dataGrid, Mode=TwoWay}" Margin="4" />
                <TextBlock Style="{StaticResource ApiName}" Text="RowDetailsVisibilityMode" Margin="4" />
                <ComboBox SelectedItem="{Binding RowDetailsVisibilityMode, ElementName=dataGrid, Mode=TwoWay}" Margin="4" SelectedIndex="2">
                    <sys:String>Collapsed</sys:String>
                    <sys:String>Visible</sys:String>
                    <sys:String>VisibleWhenSelected</sys:String>
                </ComboBox>
                <TextBlock Style="{StaticResource ApiName}" Text="SelectionMode" Margin="4" />
                <ComboBox SelectedItem="{Binding SelectionMode, ElementName=dataGrid, Mode=TwoWay}" Margin="4" SelectedIndex="1">
                    <sys:String>Single</sys:String>
                    <sys:String>Extended</sys:String>
                </ComboBox>
                <TextBlock Margin="4" Style="{StaticResource Information}">
                    <LineBreak />
                    Things to try:
                    <LineBreak /><LineBreak />
                    1. Sort by clicking a column header.
                    <LineBreak />
                    2. Sort by multiple columns by holding Shift and clicking column headers.
                    <LineBreak />
                    3. Reorganize columns by clicking and dragging the column header.
                    <LineBreak />
                    4. Resize columns by clicking and dragging the edge of the column header.
                    <LineBreak />
                    5. Enter edit mode for a cell by double-clicking or selecting it and hitting F2.
                    <LineBreak />
                    6. Hit the escape key to cancel editing of a cell.  Hit escape twice to cancel editing the entire row.
                    <LineBreak />
                    7. Double click a group header to expand or collapse the group.
                    <LineBreak />
                    8. Enter an invalid phone number or remove a contact's name to see a validation error.
                </TextBlock>
            </StackPanel>
            <datagrid:DataGrid x:Name="dataGrid" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top" MinWidth="400" Margin="4" MaxHeight="300" Grid.Column="1">
                <datagrid:DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <StackPanel Background="LightBlue">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="This item has details." />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Here is some data: " />
                                <TextBlock Text="{Binding FirstName}" />
                                <TextBlock Text=" " />
                                <TextBlock Text="{Binding LastName}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </datagrid:DataGrid.RowDetailsTemplate>
            </datagrid:DataGrid>
        </Grid>
        <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="DataGridGroupingSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;UserControl x:Class="System.Windows.Controls.Samples.DataGridGroupingSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:datagrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt;
    &lt;StackPanel&gt;
        &lt;ContentControl Content="DataGrid with Grouping" Style="{StaticResource Header}" /&gt;
        &lt;Grid&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition /&gt;
                &lt;ColumnDefinition /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;StackPanel Grid.Column="0"&gt;
                &lt;CheckBox Content="AreRowDetailsFrozen" IsChecked="{Binding AreRowDetailsFrozen, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;CheckBox Content="AreRowGroupHeadersFrozen" IsChecked="{Binding AreRowGroupHeadersFrozen, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;CheckBox Content="CanUserReorderColumns" IsChecked="{Binding CanUserReorderColumns, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;CheckBox Content="CanUserResizeColumns" IsChecked="{Binding CanUserResizeColumns, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;CheckBox Content="CanUserSortColumns" IsChecked="{Binding CanUserSortColumns, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;TextBlock Style="{StaticResource ApiName}" Text="FrozenColumnCount" Margin="4" /&gt;
                &lt;input:NumericUpDown VerticalAlignment="Center" Minimum="0" Margin="4" Value="{Binding FrozenColumnCount, ElementName=dataGrid, Mode=TwoWay}" /&gt;
                &lt;CheckBox Content="IsReadOnly" IsChecked="{Binding IsReadOnly, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;CheckBox Content="IsValid" IsChecked="{Binding IsValid, ElementName=dataGrid, Mode=TwoWay}" Margin="4" /&gt;
                &lt;TextBlock Style="{StaticResource ApiName}" Text="RowDetailsVisibilityMode" Margin="4" /&gt;
                &lt;ComboBox SelectedItem="{Binding RowDetailsVisibilityMode, ElementName=dataGrid, Mode=TwoWay}" Margin="4" SelectedIndex="2"&gt;
                    &lt;sys:String&gt;Collapsed&lt;/sys:String&gt;
                    &lt;sys:String&gt;Visible&lt;/sys:String&gt;
                    &lt;sys:String&gt;VisibleWhenSelected&lt;/sys:String&gt;
                &lt;/ComboBox&gt;
                &lt;TextBlock Style="{StaticResource ApiName}" Text="SelectionMode" Margin="4" /&gt;
                &lt;ComboBox SelectedItem="{Binding SelectionMode, ElementName=dataGrid, Mode=TwoWay}" Margin="4" SelectedIndex="1"&gt;
                    &lt;sys:String&gt;Single&lt;/sys:String&gt;
                    &lt;sys:String&gt;Extended&lt;/sys:String&gt;
                &lt;/ComboBox&gt;
                &lt;TextBlock Margin="4" Style="{StaticResource Information}"&gt;
                    &lt;LineBreak /&gt;
                    Things to try:
                    &lt;LineBreak /&gt;&lt;LineBreak /&gt;
                    1. Sort by clicking a column header.
                    &lt;LineBreak /&gt;
                    2. Sort by multiple columns by holding Shift and clicking column headers.
                    &lt;LineBreak /&gt;
                    3. Reorganize columns by clicking and dragging the column header.
                    &lt;LineBreak /&gt;
                    4. Resize columns by clicking and dragging the edge of the column header.
                    &lt;LineBreak /&gt;
                    5. Enter edit mode for a cell by double-clicking or selecting it and hitting F2.
                    &lt;LineBreak /&gt;
                    6. Hit the escape key to cancel editing of a cell.  Hit escape twice to cancel editing the entire row.
                    &lt;LineBreak /&gt;
                    7. Double click a group header to expand or collapse the group.
                    &lt;LineBreak /&gt;
                    8. Enter an invalid phone number or remove a contact's name to see a validation error.
                &lt;/TextBlock&gt;
            &lt;/StackPanel&gt;
            &lt;datagrid:DataGrid x:Name="dataGrid" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Top" MinWidth="400" Margin="4" MaxHeight="300" Grid.Column="1"&gt;
                &lt;datagrid:DataGrid.RowDetailsTemplate&gt;
                    &lt;DataTemplate&gt;
                        &lt;StackPanel Background="LightBlue"&gt;
                            &lt;StackPanel Orientation="Horizontal"&gt;
                                &lt;TextBlock Text="This item has details." /&gt;
                            &lt;/StackPanel&gt;
                            &lt;StackPanel Orientation="Horizontal"&gt;
                                &lt;TextBlock Text="Here is some data: " /&gt;
                                &lt;TextBlock Text="{Binding FirstName}" /&gt;
                                &lt;TextBlock Text=" " /&gt;
                                &lt;TextBlock Text="{Binding LastName}" /&gt;
                            &lt;/StackPanel&gt;
                        &lt;/StackPanel&gt;
                    &lt;/DataTemplate&gt;
                &lt;/datagrid:DataGrid.RowDetailsTemplate&gt;
            &lt;/datagrid:DataGrid&gt;
        &lt;/Grid&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DataGridGroupingSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.ComponentModel;
using System.Windows.Data;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample page demonstrating the DataGrid with grouping enabled.
    /// &lt;/summary&gt;
    [Sample("DataGrid with Grouping", DifficultyLevel.Intermediate)]
    [Category("DataGrid")]
    public partial class DataGridGroupingSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a DataGridGroupingSample.
        /// &lt;/summary&gt;
        public DataGridGroupingSample()
        {
            InitializeComponent();
            PagedCollectionView pcv = new PagedCollectionView(Contact.People);
            pcv.GroupDescriptions.Add(new PropertyGroupDescription("State"));
            pcv.GroupDescriptions.Add(new PropertyGroupDescription("City"));
            DataContext = pcv;
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DataGridGroupingSample.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports System.ComponentModel
Imports System.Windows.Data

''' &lt;summary&gt;
''' Sample page demonstrating the DataGrid with grouping enabled.
''' &lt;/summary&gt;
&lt;Sample("DataGrid with Grouping", DifficultyLevel.Basic)&gt; _
&lt;Category("DataGrid")&gt; _
Public Class DataGridGroupingSample
    Inherits UserControl

    ''' &lt;summary&gt;
    ''' Initializes a DataGridGroupingSample.
    ''' &lt;/summary&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification:="InitializeComponent Required by Visual Studio.")&gt; _
    Public Sub New()
        InitializeComponent()
        Dim pcv As PagedCollectionView = New PagedCollectionView(Contact.People)
        pcv.GroupDescriptions.Add(New PropertyGroupDescription("State"))
        pcv.GroupDescriptions.Add(New PropertyGroupDescription("City"))
        DataContext = pcv
    End Sub
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </StackPanel>
</UserControl>
